<?php


namespace App\Http\Model\Job;


use Illuminate\Support\Facades\DB;

class PfsHeadQueryHostDetailModel
{

    /**
     * 3.7监管户动账查询>机构端>银行:新增记录
     *
     * @param $data
     * @param $list
     */
    public static function ins($data, $list)
    {
        $tranSerialExist = [];
        /*查询已存在的流水*/
        $exist = DB::select('SELECT `tran_serial` FROM `pfs_query_host_detail` WHERE `pfs_dw_id`=:pfs_dw_id AND `tran_date`>=:begin_date AND `tran_date`<=:end_date', [
            'pfs_dw_id'  => $data['pfs_dw_id'],
            'begin_date' => $data['begin_date'],
            'end_date'   => $data['end_date'],
        ]);
        if (!empty($exist)) {
            foreach ($exist as $val) {
                $tranSerialExist[$val->tran_serial] = 1;
            }
        }
        $ins = [];
        foreach ($list as $val) {
            /*如果流水号已经存在,则跳过处理*/
            if (isset($tranSerialExist[$val->tranSerial])) {
                continue;
            }
            $ins[] = [
                /*主体*/
                'ledger_subject_id'   => $data['ledger_subject_id'],
                'ledger_subject_name' => $data['ledger_subject_name'],
                /*城市*/
                'city_name'           => $data['city_name'],
                'area_code'           => $data['area_code'],
                /*招行&数仓-业务线分校配置信息主键ID*/
                'pfs_dw_id'           => $data['pfs_dw_id'],
                /*监管户户口号*/
                'reg_acc_no'          => $val->regAccNo,
                /*交易状态，固定为S（成功）*/
                'tran_status'         => $val->tranStatus,
                /*交易流水*/
                'tran_serial'         => $val->tranSerial,
                /*交易金额*/
                'tran_amt'            => $val->tranAmt,
                /*清算摘要*/
                'tag'                 => $val->tag,
                /*借贷标志   C：贷； D借*/
                'tran_dir'            => $val->tranDir,
                /*清算日期，格式：YYYY-MM-DD*/
                'tran_date'           => $val->tranDate,
                /*清算时间，格式：HH:mm:ss*/
                'tran_time'           => $val->tranTime,
                /*币种，10（人民币）*/
                'currency'            => $val->currency,
                /*收付方帐号*/
                'rcv_pay_acc'         => $val->rcvPayAcc,
                /*收付方名称*/
                'rcv_pay_name'        => $val->rcvPayName,
                /*收付方开户行*/
                'rcv_pay_ebk'         => $val->rcvPayEbk,
                /*收付方开户行联行号*/
                'rcv_pay_ebb'         => $val->rcvPayEbb,
            ];
        }
        DB::table('pfs_query_host_detail')->insert($ins);
    }


}





/**
 * PfsHeadQueryHostDetailModel.php
 *
 * 说明:
 *
 * 修改历史
 * ----------------------------------------
 * 2021/6/9 16:53:00   操作:创建
 **/
